package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingcartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: ShoppingCartController
 * Package: IntelliJ IDEA
 *
 * @author 张文豪
 * @description
 * @date 2023/8/18 14:47
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api("购物车相关接口")
public class ShoppingCartController {
    @Autowired
    private ShoppingcartService shoppingcartService;
    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("购物车添加：{}",shoppingCartDTO);
        shoppingcartService.add(shoppingCartDTO);
        return Result.success();
    }
    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> listShopCar(){
        log.info("查看购物车");
        List<ShoppingCart> list = shoppingcartService.listShopCart();
        return Result.success(list);
    }
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result cleanAll(){
        log.info("开始清空");
        shoppingcartService.clean();
        return Result.success();
    }
    @PostMapping("/sub")
    @ApiOperation("删除一个")
    public Result cleanSingle(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("开始删除");
        shoppingcartService.deleteSingle(shoppingCartDTO);
        return Result.success();
    }
}
